< previous page page_820 next page >

Page 820
Creating an Index
You can create a single-field or multi-field index with the CREATE INDEX statement. To create the index, you must give the name of the index, the name of the table for the index, and at least one field to be included in the index. You can specify ascending or descending order for each field. You can also specify that the index is a primary index for the table. Listing C.21 shows how to create a primary index on customer number and a two-field index with the sort orders specified. These indexes are set up for the Customers table of the sample case.
Listing C.21 CREATEIND.TXTCreate Several Types of Indexes with the CREATE INDEX Statement
'*****************************************
'Create a primary index on customer number
'*****************************************
CREATE INDEX Custno ON Customers (Custno) WITH PRIMARY
'*************************************************************
'Create a two field index with ascending order on Lastname and 
'   descending order on Firstname.
'*************************************************************
CREATE INDEX Name2 ON Customers (Lastname ASC, Firstname DESC)
Deleting an Index
Getting rid of an index is just as easy as creating one. To delete an index from a table, use the DROP INDEX statement as shown in the following example. These statements delete the two indexes created in Listing C.21. Notice that you must specify the table name for the index that you want to delete:
DROP INDEX Custno ON Customers
DROP INDEX Name2 ON Customers
Using SQL
As stated at the beginning of the chapter, you can't place a SQL statement by itself in a program. It must be part of another function. This part of the chapter describes the various methods used to implement the SQL statements.
Executing an Action Query
The Jet engine provides an execute method as part of the database object. The execute method tells the engine to process the SQL query against the database. An action query can be executed by specifying the SQL statement as part of the execute method for a database. An action query can also be used to create a QueryDef. Then the query can be executed on its own. Listing C.22 shows how both of these methods are used to execute the same SQL statement.

 
< previous page page_820 next page >